package manager.com.ithei.edu.info.manager.dao;

import manager.com.ithei.edu.info.manager.domain.Teacher;

import java.text.ParseException;
import java.util.concurrent.TransferQueue;

public class TeacherDao implements BaseTeacherDao{
    private  static Teacher[] teacher=new Teacher[10];

    @Override
    public Teacher[] findAllTeachers(){
        return teacher;
    }

    @Override
    public boolean addTeacher(Teacher stu) throws ParseException {
        int index=-1;
        for (int i = 0; i < teacher.length; i++) {
            Teacher tea=new Teacher();
            if(teacher[i]==null){
                index=i;
                break;
            }
        }
        if(index==-1){
            return false;
        }
        teacher[index]=stu;
        return true;
    }

    //获取学号对应对象的索引
    @Override
    public int getIndex(String id){
        int index = -1;
        for (int i = 0; i < teacher.length; i++) {
            Teacher tea = teacher[i];
            if(tea != null && tea.getSid().equals(id)){
                index = i;
                break;
            }
        }
        return index;
    }

    //删除教师的方法
    @Override
    public void deleteTeacherByIdTwo(String id) {
        teacher[getIndex(id)]=null;
    }

    @Override
    public void setTeacherByIdTwo(String id, Teacher teachers) {
        //通过学号查找数组中对应的索引值
        int index=getIndex(id);
        //让给定学生对象覆盖指定索引位置的元素(对象)
        teacher[index]=teachers;
    }

}
